def scan_ip(ipadress):
    try:
        ips = IPy.IP(ipadress)
        if os.path.isfile('enables_ips.txt'):
            fp = open('ips.txt', 'w')
        else:
            fp = open('ips.txt', 'x')
        for ip in ips:
            result = subprocess.run('ping -n 1 -w 1 ' + str(ip))
            if result.returncode == 0:
                fp.write(str(ip) + '\n')
                fp.flush()
    except ValueError as fi:
        print("ip地址输入错误")
    except Exception as fe:
        print(fe)
scan_ip('192.168.0.0/24')